Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sanitizer to disable auto lightbox #6936

Merged
merged 9 commits into from
Mar 9, 2022

Conversation

dhaval-parekh
Copy link
Collaborator

@dhaval-parekh dhaval-parekh commented Feb 24, 2022

Summary

Fixes #5122

Add sanitiser to disable auto lightbox by adding data-amp-auto-lightbox-disable attribute to body element.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@dhaval-parekh dhaval-parekh marked this pull request as ready for review March 3, 2022 05:45
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

Plugin builds for 7a3d259 are ready 🛎️!

@@ -1608,6 +1608,12 @@ function amp_get_content_sanitizers( $post = null ) {
);
}

$is_auto_lightbox_disabled = apply_filters( 'amp_auto_lightbox_disabled', true );

if ( ! $is_auto_lightbox_disabled ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an opposite of what should be. If $is_auto_lightbox_disabled is true, we should use AMP_Auto_Lightbox_Disable_Sanitizer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it should be vice versa.
However current implementation is based on the Implementation brief of the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant here is that the variable name says is_auto_lightbox_disabled and when it was true (i.e. disabled) we actually enabled the auto lightbox feature - so the opposite.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant here is that the variable name says is_auto_lightbox_disabled and when it was true (i.e. disabled) we actually enabled the auto lightbox feature - so the opposite.

@dhaval-parekh dhaval-parekh self-assigned this Mar 8, 2022
@dhaval-parekh dhaval-parekh requested a review from delawski March 8, 2022 12:10
@@ -1608,6 +1608,12 @@ function amp_get_content_sanitizers( $post = null ) {
);
}

$is_auto_lightbox_disabled = apply_filters( 'amp_auto_lightbox_disabled', false );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be true by default? The acceptance criteria in #5122 says:

By default the data-amp-auto-lightbox-disable attribute should be added to the body.

The code above doesn't add the data-amp-auto-lightbox-disable attribute by default.

Copy link
Member

@westonruter westonruter Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late to respond to #5122 (comment).

After thinking about it some more, I think it's probably good to indeed disable by default. Otherwise, users who see the Lightbox toggle will be confused what purpose it serves if the images are lightboxed anyway.

Suggested change
$is_auto_lightbox_disabled = apply_filters( 'amp_auto_lightbox_disabled', false );
$is_auto_lightbox_disabled = apply_filters( 'amp_auto_lightbox_disabled', true );

Comment on lines 1910 to 1920
$this->assertContains(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
array_keys( amp_get_content_sanitizers() )
);

remove_all_filters( 'amp_auto_lightbox_disabled' );

$this->assertNotContains(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
array_keys( amp_get_content_sanitizers() )
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertContains(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
array_keys( amp_get_content_sanitizers() )
);
remove_all_filters( 'amp_auto_lightbox_disabled' );
$this->assertNotContains(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
array_keys( amp_get_content_sanitizers() )
);
$this->assertArrayHasKey(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
amp_get_content_sanitizers()
);
remove_all_filters( 'amp_auto_lightbox_disabled' );
$this->assertArrayNotHasKey(
AMP_Auto_Lightbox_Disable_Sanitizer::class,
amp_get_content_sanitizers()
);

* @return void
*/
public function sanitize() {
$this->dom->body->setAttributeNode( $this->dom->createAttribute( 'data-amp-auto-lightbox-disable' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good to use createAttribute as then no attribute value will be shown. 👍

dhaval-parekh and others added 4 commits March 9, 2022 18:19
…nt/5122-disabled-auto-lightbox

* 'develop' of github.com:ampproject/amp-wp: (181 commits)
  Copy referrerpolicy attribute from img to amp-pixel
  Improve nav menu E2E tests by creating test menu before each test suite
  Bail out if there is no menu location or it is already selected
  Add E2E tests for Twenty Twenty-Two header nav menu block
  Test Twenty Twenty search modal on mobile breakpoint
  Remove redundant space
  Use `Extension` class constant for getting `amp-pixel` tag name
  Add missing replacement string to `str_replace` and reformat
  Use `::class` constant instead of hardcoded class name
  Examine parsed URL instead of using regex
  Remove `amp-pixel` from selector conversion mapping
  Bump dependabot/fetch-metadata from 1.1.1 to 1.3.0
  Improve strings to account for one or more issues
  Fix type check by passing explicit string as href prop
  Include SCSS files in the lint-staged config for stylelint
  Fix stylelint issue
  Replace `img` with `amp-pixel` when dealing with Facebook tracking pixel
  Rename 'allowed' to 'associated'
  Use named functions
  Add label for why the validation data is being shown
  ...
@westonruter westonruter changed the title Add sanitiser to disable auto lightbox Add sanitizer to disable auto lightbox Mar 9, 2022
@westonruter westonruter merged commit fe0000b into develop Mar 9, 2022
@westonruter westonruter deleted the enhancement/5122-disabled-auto-lightbox branch March 9, 2022 18:52
westonruter added a commit that referenced this pull request Mar 9, 2022
@westonruter westonruter added this to the v2.2.2 milestone Mar 18, 2022
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All images in a post have lightbox when no image is explicitly opted into lightbox
3 participants